const {BaseService} = require('../../basic.js')
const {
	PictureModel
} = require('dx-func-entity')
const _ = require('underscore');
// const {
// 	buildMenus
// } = require('../util/util.js')

module.exports = class Pictsure extends BaseService {
	constructor(ctx) {
		super(ctx);
		this.entity = PictureModel;		
	}
	findByIds(_ids){
		return this.where('_id','IN',_ids).limit(3000).field('name').select(true);
	}
	async loadTagList(key,list){
		const taglist = [];
		_.each(list,item=>{
			if(_.isArray(item[key])){
				taglist.push(...item[key]);
			}
		})
		const _tids = _.filter(taglist,item=>_.isString(item));
		const tags = await this.findByIds(_tids);
		//console.info('查找用户数量：',_hids.length,hrusers.length);
		for (let i = 0; i < list.length; i++) {
			list[i][key+'s'] = list[i][key].map(_id=>{
				if(_.isString(_id)){
					const tag = _.findWhere(tags,{_id})
					return tag
				}
				return _id;
			});
		}
		return list;
	}
}
